package com.intel.two.controller.community;

import com.intel.two.common.LayuiPageVo;
import com.intel.two.common.R;
import com.intel.two.pojo.community.Procter;
import com.intel.two.service.community.ProcterService;
import com.intel.two.vo.community.procterBarVo;
import com.intel.two.vo.community.procterPieVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/procter")
public class ProcterController {
    @Autowired
    private ProcterService procterService;
    /*查全部+分页*/
    @RequestMapping("/procterList")
    public LayuiPageVo<Procter> procterPageData(@RequestParam Map<String, Object> params) {
        System.out.println(params);
        return procterService.procterPageData(params);
    }
    @GetMapping("/deleteProcter")
    public R deleteProcter(Integer procter_id) {

        int result = procterService.deleteProcter(procter_id);
        if (result == 1) {
            return R.ok();
        } else {
            return R.error();
        }
    }

    @GetMapping("/deleteProcterAll")
    public R deleteProcterAll(@RequestParam Map<String, Object> map) {
        int result = procterService.deleteProcterAll(map);
        if (result > 0) {
            return R.ok();
        } else {
            return R.error();
        }
    }
    /*添加*/
    @PostMapping("/addProcter")
    public R addProcter(Procter procter) {
        System.out.println(procter);

        int result = procterService.addProcter(procter);

        if (result == 1) {
            return R.ok();
        } else {
            return R.error();
        }
    }
    @PostMapping("updateProcter")
    public R updateProcter(Procter procter) {
        System.out.println(procter);
        int result = procterService.updateProcter(procter);
        if (result == 1) {
            return R.ok();
        } else {
            return R.error();
        }
    }
    @RequestMapping("/procterBar")
    public R procterBar(){
        List<procterBarVo> list = procterService.procterBar();
        return R.ok().data("sexBar",list);
    }
    @RequestMapping("/procterPie")
    public R procterPie(){
        List<procterPieVo> list = procterService.procterPie();
        return R.ok().data("sexPic",list);
    }
}
